/**
 * 
 */
package ae.pcfc.cldos.online.web.controller.client.company.vv.cancel;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import ae.pcfc.cldos.online.common.ConstantsCommon.Steps;
import ae.pcfc.cldos.online.common.delegate.VisitVisaCancelDelegate;
import ae.pcfc.cldos.online.common.vo.FileVO;
import ae.pcfc.cldos.online.common.vo.vv.cancel.VisitVisaCancelVO;
import ae.pcfc.cldos.online.web.ViewPath;
import ae.pcfc.cldos.online.web.ViewUtils;
import ae.pcfc.cldos.online.web.model.VVCancelModel;

/**
 * 
 * @author akhader
 *
 */
@Controller
@RequestMapping(value = ViewPath.__ADMIN_EMPLOYMENT_VISA_CANCEL_VIEW)
public class VVCancelViewController extends VVCancelBase{
	
	@Autowired
	@Qualifier("visitVisaCancelDelegate")
	private VisitVisaCancelDelegate visitVisaCancelDelegate;
	

	@ModelAttribute
	public void populateBreadCrumbs(ModelMap model, @RequestParam String appId) {
		breadCrumbsFactoryService.populateallAppReqDtlBreadCrumb(model);
	}
	
	@ModelAttribute("vvCancelModel")
	public VVCancelModel populateRegisterEmploymentVisaReviewerInfoModel(@RequestParam String appId,
			HttpServletRequest request, ModelMap model) throws Exception {
		VVCancelModel vvCancelModel = new VVCancelModel();
		
		VisitVisaCancelVO visitVisaCancelVO =
				visitVisaCancelDelegate.getEmploymentVisaCancelationAppInfo(
						encryptionDelegate.decodeAndDecrypt(appId), getUserVO(), Steps.ALL_APP_REQUEST);
		
		List<FileVO> fileVOList = visitVisaCancelVO.getFileVOList();
		model.put("files", fileVOList);
		model.put("exitDocument", visitVisaCancelVO.getExitDocument());
		model.put("comments", visitVisaCancelVO.getApplicationCommentVOs());
		
		mapper.map(visitVisaCancelVO.getVisaCancelDetailsVO(), vvCancelModel);
		vvCancelModel.setWfStatus(visitVisaCancelVO.getWfStatus());
		model.put("appId", appId);
		return vvCancelModel;
	}
	

	
	@RequestMapping(value = "/form.htm", method = RequestMethod.GET)
	public ModelAndView form() {
		return ViewUtils.DEFAULT_VIEW;
	}
	

	
}
